'use strict';
const { Model } = require('sequelize');
module.exports = (sequelize, DataTypes) => {
    class content extends Model {
        static associate(models) {
            content.belongsTo(models.user,{
                foreignKey:'user_id'
            })
        }
    };
    content.init({
        id: {
            type: DataTypes.INTEGER,
            allowNull: false,
            autoIncrement: true,
            primaryKey: true,
        },
        user_id: {      // 外键表
            type: DataTypes.INTEGER,
            allowNull: false,
            references: {       // 关联user表的id字段
                model: Model.user,
                key: 'id'
            }
        },
        title: {
            type: DataTypes.STRING(50),
            allowNull: false,
            defaultValue: ''
        },
        content: {
            type: DataTypes.STRING(1000),
            allowNull: false,
            defaultValue: ''
        },
        link_count: {
            type: DataTypes.INTEGER,
            allowNull: false,
            defaultValue: 0
        },
        comment_count: {
            type: DataTypes.INTEGER,
            allowNull: false,
            defaultValue: 0
        }
    },{
        sequelize,
        modelName:'content'
    });
    return content;
}